//
//  YellowPageCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/2.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "YellowPageCell.h"
#import "ImageBrowser.h"
@interface YellowPageCell ()
@property (weak, nonatomic) IBOutlet UIImageView *leftImageView;
@property (weak, nonatomic) IBOutlet UILabel *topLeftLabel;
@property (weak, nonatomic) IBOutlet UILabel *topRightLabel;
@property (weak, nonatomic) IBOutlet UILabel *middleLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *contactLabel;
@property (weak, nonatomic) IBOutlet UIButton *phoneBtn;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightLabelW;
@property (weak, nonatomic) IBOutlet ImageBrowser *myCollcetionVeiw;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (nonatomic, strong) NSMutableArray<NSURL *> *urls;
@end

@implementation YellowPageCell

- (NSMutableArray<NSURL *> *)urls{
    
    if (!_urls) {
        
        _urls = [[NSMutableArray alloc]init];
    }
 
    return _urls;
}

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    self.bottomMargin.constant = 0;
    self.leftMargin.constant = 20;
    self.rightMargin.constant = 20;
    self.topLeftLabel.font = MYFONT(16);
    self.topRightLabel.font = MYFONT(14);
    self.middleLabel.font = MYFONT(13);
    self.addressLabel.font = MYFONT(13);
    self.contactLabel.font = MYFONT(15);
    self.phoneBtn.titleLabel.font = MYFONT(15);
    self.phoneBtn.backgroundColor = [UIColor whiteColor];
    [self.phoneBtn setTitleColor:themeColor forState:UIControlStateNormal];
    [self.phoneBtn setTitleColor:themeColor forState:UIControlStateHighlighted];
    self.phoneBtn.layer.borderColor = themeColor.CGColor;
    self.phoneBtn.layer.borderWidth = 0.6;

    
    self.topRightLabel.textColor = darkGray;
    self.middleLabel.textColor = darkGray;
    self.addressLabel.textColor = darkGray;
    self.contactLabel.textColor = darkGray;
    
    self.topRightLabel.layer.borderColor = lineGray.CGColor;
    
    self.topRightLabel.layer.borderWidth = 0.6;
    
    self.topRightLabel.layer.cornerRadius = 3;
    
    self.topRightLabel.layer.masksToBounds = YES;
    
    self.phoneBtn.layer.cornerRadius = 5;
    
    self.phoneBtn.layer.masksToBounds = YES;
    
    self.lineView.backgroundColor = viewBgGrey;
    
    // Initialization code
}


//
//
//return CGSizeMake(size.width + 12,26);

- (void)setModel:(YellowPageListModel *)model{
    
    _model = model;
    
    [self.urls removeAllObjects];
    
//    _model.pic = @"http://img000.hc360.cn/g6/M05/FC/B5/wKhQr1PDb8qEWEoUAAAAAJvJItc274.jpg";
    
    
//    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:_model.pic] placeholderImage:nil];
    
    self.topLeftLabel.text = _model.supplier_name;
    
    NSString *hehe = [NSString stringWithFormat:@"%@",_model.name];
    
    CGSize size = [hehe sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MYFONT(14), NSFontAttributeName, nil]];

    self.rightLabelW.constant = size.width + 12;
    
    self.topRightLabel.text = hehe;
    
    self.middleLabel.attributedText = [self attributedString0];
    
    
    self.addressLabel.attributedText = [self attributedString1] ;
    
    
    self.contactLabel.attributedText = [self attributedString2];

    
//    self.addressLabel.text = @"地址:地址:地址";
    [self.phoneBtn setTitle:[NSString stringWithFormat:@" %@",_model.linkman_tel] forState:UIControlStateNormal];
    [self.phoneBtn setTitle:[NSString stringWithFormat:@" %@",_model.linkman_tel] forState:UIControlStateHighlighted];
    
//    self.myCollcetionVeiw.hidden = YES;
    
    if (_model.pic.length > 0) {
        self.myCollcetionVeiw.userInteractionEnabled = YES;
      

        [self.urls addObject:[NSURL URLWithString:_model.pic]];
        
        self.myCollcetionVeiw.thumPicURLs = self.urls;
        
        BrowserLayout *layout = (BrowserLayout *)self.myCollcetionVeiw.collectionViewLayout;
        
        layout.itemSize = CGSizeMake(120, 90);
        
        [self.myCollcetionVeiw reloadData];
    } else {
        
        self.myCollcetionVeiw.userInteractionEnabled = NO;
        [self.urls addObject:[NSURL URLWithString:_model.pic]];
        
        self.myCollcetionVeiw.thumPicURLs = self.urls;
        
        BrowserLayout *layout = (BrowserLayout *)self.myCollcetionVeiw.collectionViewLayout;
        
        layout.itemSize = CGSizeMake(120, 90);
        
        [self.myCollcetionVeiw reloadData];
    }
    
   
    
}

- (IBAction)phoneBtnDidTap:(UIButton *)sender {
    
    NSMutableString * str = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",self.model.linkman_tel];
    
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:str]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

    } else {
        [SVProgressHUD showInfoWithStatus:@"号码格式错误!"];
    }
    
}


- (NSMutableAttributedString *)attributedString0{
//    [NSString stringWithFormat:@"主营业务: %@",_model.desc];
    UIFont *bigFont = [UIFont boldSystemFontOfSize:14];
    UIFont *smallFont = MYFONT(13);
    NSMutableAttributedString *attributeString6 = [[NSMutableAttributedString alloc] init];
    NSAttributedString *string26 = [[NSAttributedString alloc] initWithString:@"主营业务: " attributes:@{NSFontAttributeName : bigFont,NSForegroundColorAttributeName : [UIColor blackColor]}];
    NSAttributedString *string27 = [[NSAttributedString alloc] initWithString:_model.desc attributes:@{NSFontAttributeName : smallFont,NSForegroundColorAttributeName : [UIColor blackColor]}];
    
    
    NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc]init];
    
    para.lineSpacing = 3;

    [attributeString6 appendAttributedString:string26];
    [attributeString6 appendAttributedString:string27];
    
    [attributeString6 addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, attributeString6.length)];
    
    return attributeString6;
    
    
}





- (NSMutableAttributedString *)attributedString1{

    
    UIFont *bigFont = [UIFont boldSystemFontOfSize:14];
    UIFont *smallFont = MYFONT(13);
    NSMutableAttributedString *attributeString6 = [[NSMutableAttributedString alloc] init];
    NSAttributedString *string26 = [[NSAttributedString alloc] initWithString:@"地址: " attributes:@{NSFontAttributeName : bigFont,NSForegroundColorAttributeName : [UIColor blackColor]}];
    NSAttributedString *string27 = [[NSAttributedString alloc] initWithString:_model.linkman_address attributes:@{NSFontAttributeName : smallFont,NSForegroundColorAttributeName : [UIColor blackColor]}];
    
    [attributeString6 appendAttributedString:string26];
    [attributeString6 appendAttributedString:string27];
    
    return attributeString6;
    
    
}





- (NSMutableAttributedString *)attributedString2{
    
    UIFont *bigFont = [UIFont boldSystemFontOfSize:16];
    UIFont *smallFont = MYFONT(15);
    NSMutableAttributedString *attributeString6 = [[NSMutableAttributedString alloc] init];
    NSAttributedString *string26 = [[NSAttributedString alloc] initWithString:@"联系人: " attributes:@{NSFontAttributeName : bigFont,NSForegroundColorAttributeName : themeColor}];
    NSAttributedString *string27 = [[NSAttributedString alloc] initWithString:_model.linkman_name attributes:@{NSFontAttributeName : smallFont,NSForegroundColorAttributeName : themeColor}];
    
    [attributeString6 appendAttributedString:string26];
    [attributeString6 appendAttributedString:string27];
    
    return attributeString6;
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
    
    

}

@end
